package com.sharekitchen.mapper;

import com.sharekitchen.entity.Admin;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
@Transactional
public interface AdminMapper {
    //    查找管理员是否存在
    @Select("SELECT COUNT(*)>0 FROM `admin` WHERE admin_name=#{adminName} AND is_delete=0")
    Boolean existAdminName(String adminName);

    //    添加admin管理员
    @Insert("INSERT INTO `admin`(admin_name, password,authority) VALUES(#{adminName}, #{password},#{authority})")
    int addAdmin(Admin admin);

    //    获取admin的信息
    @Select("SELECT * FROM `admin` WHERE admin_name=#{adminName}  AND is_delete=0 ")
    Admin findAdminByName(String adminName);

    //    获取admin的信息
    @Select("SELECT * FROM `admin` WHERE admin_id=#{adminId}  AND is_delete=0 ")
    Admin findAdminById(int adminId);

    //    获取全部admin的信息
    @Select("SELECT * FROM `admin` WHERE is_delete=0 ")
    List<Admin> findAllAdmin();

    @Update("UPDATE `admin` SET `is_delete`=1 WHERE admin_name=#{adminName} AND is_delete=0")
    Boolean deleteAdminByName(String adminName);

    @Update("UPDATE `admin` SET admin_name = #{adminName}, password=#{password},authority=#{authority} WHERE admin_id=#{adminId} AND is_delete=0")
    Boolean updateAdmin(Admin admin);

}
